package com.txzhang.springcloud.goodserver.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.txzhang.springcloud.goodserver.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/good")
public class GoodController {

    @Autowired
    private GoodService goodService;

    @GetMapping("/json")
    public R json(Integer id) {
        return R.ok(goodService.getById(id));
    }

    /**
     * 减少库存
     * @param goodCode 商品code
     * @param count 购买数量
     * @return
     */
    @PostMapping("/reduce")
    public R reduceGood(String goodCode, Integer count) {
        goodService.reduceGood(goodCode, count);
        return R.ok("库存减少成功！");
    }
}
